home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / mcomm551.zip / TXZM.C < prev    next >
C/C++ Source or Header  |  1991-12-14  |  48KB  |  1,377 lines

  1.  
  2. /*/////////////////////////////////////////////////////////////////////
  3. //                                                                   //
  4. //  TXZM.C -- zmodem protocol driver (formerly ZMP)                  //
  5. //                                                                   //
  6. //    (c) 1991, Mike Dumdei, 6 Holly Lane, Texarkana TX, 75503       //
  7. //                                                                   //
  8. //////////////////////////////////////////////////////////////////// */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <stdarg.h>
  12. #include <string.h>
  13. #include <process.h>
  14. #include <ctype.h>
  15. #include <io.h>
  16. #include <dos.h>
  17. #include <bios.h>
  18. #include "comm.h"
  19. #include "ansidrv.h"
  20. #include "extra.h"
  21. #include "colors.h"
  22. #include "zmdos.h"
  23.  
  24. #ifdef __TURBOC__
  25.   #include <dir.h>
  26.   #define _chdrive(d) setdisk((d)-1)
  27. #endif
  28.  
  29. #ifdef __ZTC__
  30.   #include <direct.h>
  31. #endif
  32.  
  33. #define ALT_C       0x2e00
  34. #define ALT_D       0x2000
  35. #define ALT_E       0x1200
  36. #define ALT_H       0x2300
  37. #define ALT_L       0x2600
  38. #define ALT_P       0x1900
  39. #define ALT_R       0x1300
  40. #define ALT_S       0x1f00
  41. #define ALT_X       0x2d00
  42. #define FK1         0x3b00
  43. #define PGUP        0x4900
  44. #define PGDN        0x5100
  45. #define ALT_EQU     0x8300
  46. #define X_ESC       0x011b
  47.  
  48. void AddToList(char *subdir);
  49. char *CaptureBaudRate(void);
  50. char *ConvertSecs(long secs);
  51. long ConvertTicks(long ticks);
  52. int Dial(void);
  53. void DrawBox(int row, int col, int nrows, int ncols, int color, int style);
  54. void DspZmodemScrn(void);
  55. char *ExpandSubDirs(char *fnames);
  56. int FileTransfer(void);
  57. void HelpFunc(void);
  58. void InitDefaults(void);
  59. void MiniTermMode(void);
  60. void ProcCmdLine(int argc, char * *argv);
  61. int prompt(char *buf, int maxlen);
  62. int RecurseSubDirs(char *sd);
  63. int RepeatDial(void);
  64. void SetFIFOLevels(int rxFIFOlevel, int txFIFOlevel);
  65. int SetParams(char *newparams);
  66. void usage(void);
  67. void vDisplay(int row, int col, char *format, ...);
  68. int waitfor(int ticks, ...);
  69. void ZMsg(int type, ...);
  70.  
  71. /*/////////////////////////////////////////////////////////
  72. //  Configuration structure.  Structure is used to allow //
  73. //  the defaults to be changed modifying the EXE.        //
  74. //  "TXZMCFG:" is the tag to search for to find the start//
  75. //  of the structure in the EXE.                         //
  76. //////////////////////////////////////////////////////// */
  77. struct PROTCONFIG
  78. {
  79.     char    tag[8], DLPath[80], ULPath[80];
  80.     long    LocBaud, MinFifoBaud;
  81.     int     ComBase, IRQ, Vctr;
  82.     int     h_VBufSize, h_BufSize, b_VBufSize, b_BufSize;
  83.     int     TxWindow, ZExistOpts, XYExistOpts;
  84.     int     FifoTxLvl, FifoRxLvl;
  85.     char    IgnCarrier, MsrFlow, KeepTime, EscCtl, OvlyIO;
  86.     char    Color[10], Mono[10];
  87. } cfg =
  88. {
  89.     "TXZMCFG:", "", "",
  90.     0L, 1L,
  91.     0x3f8, IRQ4, VCTR4,
  92.     2048, 0, 20508, 20480,
  93.     0, 1, 2,
  94.     8, 8,
  95.     0, 0, 1, 0, 1,
  96.     {  WHT|BLU_B,  H_GRN|BLU_B,  H_RED|BLU_B,    YLW|BLU_B,
  97.        GRY|BLU_B,    YLW|BLU_B,  H_RED|BLU_B,  H_MAG|BLU_B,
  98.        CYN,              CYN_B  },
  99.     { WHT, WHT, RVRS, H_WHT, WHT, H_WHT, H_WHT, H_WHT, WHT, WHT_B }
  100. };
  101.  
  102. /*/////////////////////////////////////////////////////////
  103. //  Screen data structure                                //
  104. //////////////////////////////////////////////////////// */
  105. typedef struct
  106. {
  107.     int row, col, color, count;
  108.     char *text;
  109. } SCREENDATA;
  110.  
  111. /*/////////////////////////////////////////////////////////
  112. //  Global variables                                     //
  113. //////////////////////////////////////////////////////// */
  114. ASYNC port;                 /* ASYNC port structure */
  115. int combase, irq, vctr;     /* port address, IRQ number, & vector */
  116. int openmask = 0;           /* mask for forcing no FIFOs, no MSR intrpts */
  117. long LocBaud = 0L;          /* CPU to modem/device baud rate */
  118. char params[12] = "";       /* port parameters */
  119. char lockedbaud[12] = "";   /* locked baud parameter */
  120. char fnames[256] = "";      /* list of files to send if sending */
  121. char minsecs[10];           /* ticks to min:secs buffer */
  122. char *color;                /* pointer to list of colors */
  123. int txtcolor;               /* color of most screen message output */
  124. char buf[256];              /* general purpose buffer */
  125. int goodargs = 0;           /* got an 'r' or an 's' on command line */
  126. char *node = NULL;          /* for bbs use: LASTUSER.BBS format file name */
  127. int miniterm = 0;           /* mini-terminal mode selected */
  128. char OvlyIO;                /* overlay disk and serial I/O flag */
  129. char *flist;                /* used when expanding subdirectories */
  130. char mask[14];              /* used when expanding subdirectories */
  131. int plen;                   /* used when expanding subdirectories */
  132. int tryDV = 0;              /* cmdline switch to test for DesqView */
  133. int checkcarrier = 0;       /* check for carrier during 'waitfor' flag */
  134. char phone[40] = "";        /* phone number to dial */
  135.  
  136. long tfBytes, tCPS;         /* total bytes transferred, average CPS */
  137. int tFiles;                 /* number of files transferred */
  138.  
  139. /*/////////////////////////////////////////////////////////
  140. //                                                       //
  141. //      Main                                             //
  142. //                                                       //
  143. //:mai////////////////////////////////////////////////// */
  144. void cdecl main(int argc, char *argv[])
  145. {
  146.     int i;
  147.     char *p1;
  148.  
  149.     color = ((initvid() & 0xff) == CO80) ? cfg.Color : cfg.Mono;
  150.     txtcolor = (int)color[1] & 0xff;
  151.     InitDefaults();
  152.     ProcCmdLine(argc, argv);
  153.     if (!goodargs)
  154.         usage();
  155.  
  156.     if (tryDV && TestDesqView() != 0)
  157.     {
  158.         i = DV_VideoSeg(v_seg);
  159.         if (v_seg != i)
  160.             v_seg = i, v_snow = 0;
  161.     }
  162.     if (*params)
  163.         ConnectBaud = atol(params);
  164.     if (*lockedbaud)
  165.         LocBaud = atol(lockedbaud);
  166.     if (LocBaud == 0L)
  167.         LocBaud = ConnectBaud;
  168.     if (LocBaud != 0L)
  169.     {
  170.         sprintf(params, "%ldN81", LocBaud);
  171.         if (LocBaud < cfg.MinFifoBaud)
  172.             openmask |= 0x4000;
  173.     }
  174.  
  175.     if (OvlyIO)
  176.         VBufSize = cfg.h_VBufSize, BufSize = cfg.h_BufSize;
  177.     else
  178.         VBufSize = cfg.b_VBufSize, BufSize = cfg.b_BufSize;
  179.     if (BufSize)
  180.         ZFR0 &= ~CANOVIO;
  181.  
  182.     AllocRingBuffer(&port, 2048, 4096, 0);
  183.     while (1)
  184.     {
  185.         i = async_open(&port, combase|openmask, irq, vctr, params);
  186.         if (i != 0)
  187.         {
  188.             printf("\nSerial port open error, Error code = %d\n\a", i);
  189.             exit(i - 20); /* -20 so exit code don't clash with zm result */
  190.         }
  191.         if (ConnectBaud == 0L)
  192.         {
  193.             ConnectBaud = atol(port.BPDSstr);
  194.             strcpy(params, port.BPDSstr);
  195.             if (ConnectBaud < cfg.MinFifoBaud && async_16550(&port)
  196.              && !(openmask & 0x4000))
  197.             {
  198.                 async_close(&port);
  199.                 openmask |= 0x4000;
  200.                 continue;
  201.             }
  202.         }
  203.         break;
  204.     }
  205.     async_msrflow(&port, cfg.MsrFlow);
  206.     tickhookset(1);
  207.  
  208.     if (miniterm)
  209.     {
  210.         pushscrn(0, 0, 25, 80);
  211.         SetFIFOLevels(1, 1);
  212.         MiniTermMode(), i = 0;
  213.         popscrn();
  214.     }
  215.     else
  216.     {
  217.         i = FileTransfer();
  218.         sprintf(buf, "TXZM exit code = %d", i);
  219.         v_color = WHT;
  220.         d_strat(23, 0, buf);
  221.     }
  222.     async_close(&port);
  223.     tickhookset(0);
  224.     exit(i);
  225. }
  226.  
  227. /*/////////////////////////////////////////////////////////
  228. //  AddToList                                            //
  229. //:add////////////////////////////////////////////////// */
  230. void AddToList(char *subdir)
  231. {
  232.     static char bkslsh[2] = " ";
  233.     int i, j;
  234.  
  235.     if (*(strchr(subdir, '\0') - 1) == '\\' || subdir == GetNameExt(subdir))
  236.         j = 1, *bkslsh = '\0';
  237.     else
  238.         j = 2, *bkslsh = '\\';
  239.     i = plen - 1;
  240.     plen += (strlen(subdir) + strlen(mask) + j);
  241.     flist = realloc(flist, plen);
  242.     sprintf(&flist[i], "\n%s%s%s", subdir, bkslsh, mask);
  243. }
  244.  
  245. /*/////////////////////////////////////////////////////////
  246. //  CaptureBaudRate                                      //
  247. //:cap////////////////////////////////////////////////// */
  248. char *CaptureBaudRate(void)
  249. {
  250.     int i;
  251.     static char *b[] = { "300", "300", "1200", "2400", "4800", "7200",
  252.         "9600", "14400", "19200" };
  253.  
  254.     checkcarrier = 0;
  255.     i = waitfor(18, "\r", b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8], NULL);
  256.     return ((i >= 0 && i <= 8) ? b[i] : NULL);
  257. }
  258.  
  259. /*///////////////////////////////////////////////
  260. //  ConvertSecs                                //
  261. //:con//////////////////////////////////////// */
  262. char *ConvertSecs(long secs)
  263. {
  264.     sprintf(minsecs, "%01ld:%02ld   " , secs / 60L, secs % 60L);
  265.     return(minsecs);
  266. }
  267.  
  268. /*///////////////////////////////////////////////
  269. //  ConvertTicks                               //
  270. //:con//////////////////////////////////////// */
  271. long ConvertTicks(long ticks)
  272. {
  273.     long secs = ((ticks * 10L) / 182L) + 1L;
  274.     ConvertSecs(secs);
  275.     return(secs);
  276. }
  277.  
  278. /*/////////////////////////////////////////////////////////
  279. //  Dial                                                 //
  280. //:dia////////////////////////////////////////////////// */
  281. int Dial(void)
  282. {
  283.     int rval;
  284.     char *p1;
  285.  
  286.     async_txblk(&port, phone, strlen(phone));
  287.     checkcarrier = 0;
  288.     rval = waitfor(45 * 18, "CONNECT", "BUSY", "NO CARRIER", "VOICE",
  289.      "ERROR", "NO DIALTONE", NULL);
  290.     if (rval == 0)
  291.     {
  292.         if ((p1 = CaptureBaudRate()) != NULL)
  293.             SetParams(p1);
  294.     }
  295.     return (rval);
  296. }
  297.  
  298. /*/////////////////////////////////////////////////////////
  299. //  DrawBox                                              //
  300. //:dra////////////////////////////////////////////////// */
  301. void DrawBox(int row, int col, int nrows, int ncols, int color, int style)
  302. {
  303.     static char boxchars[][6] =
  304.     {
  305.         '┌', '┐', '└', '┘', '─', '│',
  306.         '╔', '╗', '╚', '╝', '═', '║',
  307.         '╒', '╕', '╘', '╛', '═', '│',
  308.         '╓', '╖', '╙', '╜', '─', '║'
  309.     };
  310.     char *box = boxchars[style];
  311.     int i, temp = v_color;
  312.  
  313.     v_color = color;
  314.     --ncols;
  315.     scrlupat(row, col, row + nrows - 1, col + ncols, nrows);
  316.     --nrows;
  317.     ++col, --ncols, --ncols;
  318.     d_nchat(row, col, box[4], color, ncols, 1);
  319.     d_nchat(row + nrows, col, box[4], color, ncols, 1);
  320.     d_nchat(row, col, box[5], color, nrows, 0);
  321.     d_nchat(row, col + ncols, box[5], color, nrows, 0);
  322.     d_chat(row, col, box[0]);
  323.     d_chat(row, col + ncols, box[1]);
  324.     d_chat(row + nrows, col, box[2]);
  325.     d_chat(row + nrows, col + ncols, box[3]);
  326.     v_color = temp;
  327. }
  328.  
  329. /*/////////////////////////////////////////////////////////
  330. //  DspZmodemScrn                                        //
  331. //:dsp////////////////////////////////////////////////// */
  332. void DspZmodemScrn(void)
  333. {
  334.     static SCREENDATA zscrn[] =
  335.     {
  336.         {  1,  6, 2,   0, " Zmodem File " },
  337.         {  2, 71, 0, -20, "│" },
  338.         { 15,  5, 0,  64, "─" },
  339.         {  2, 73, 0,   0, "F T" },
  340.         {  3, 73, 4, -19, "▒" },
  341.         {  3, 75, 4, -19, "▒" },
  342.         {  3,  5, 0,   0, "File name :" },
  343.         {  5,  5, 0,   0, "Estimated time :" },
  344.         {  6,  5, 0,   0, "Elapsed time   :" },
  345.         {  7,  5, 0,   0, "File CPS rate  :" },
  346.         {  5, 37, 0,   0, "File position      :" },
  347.         {  6, 37, 0,   0, "Expected file size :" },
  348.         {  7, 37, 0,   0, "Beginning offset   :" },
  349.         {  9, 51, 0,   0, "─── Hdr Data ───" },
  350.         { 10, 23, 0,   0, "Header Name" },
  351.         { 10, 40, 0,   0, "Type" },
  352.         { 10, 52, 0,   0, "Hex" },
  353.         { 10, 61, 0,   0, "Decimal" },
  354.         { 11,  5, 0,   0, "Last hdr recvd :" },
  355.         { 12,  5, 0,   0, "Last hdr sent  :" },
  356.         { 14,  5, 0,   0, "Crc :" },
  357.         { 14, 37, 0,   0, "Flow :" },
  358.         { 17,  5, 0,   0, "Total files queued :" },
  359.         { 18,  5, 0,   0, "Total bytes queued :" },
  360.         { 17, 42, 0,   0, "Estimated time   :" },
  361.         { 18, 42, 0,   0, "Accumulated time :" },
  362.         { 20,  5, 0,   0, "Files transferred  :" },
  363.         { 21,  5, 0,   0, "Bytes transferred  :" },
  364.         { 21, 42, 0,   0, "Average CPS rate :" },
  365.         { -1, -1, 0,   0, "" }
  366.     };
  367.     register SCREENDATA *sd;
  368.  
  369.     v_color = WHT;
  370.     cls();
  371.     v_color = txtcolor;
  372.     DrawBox(1, 1, 22, 78, color[0], 0);
  373.     for (sd = zscrn; sd->row >= 0; ++sd)
  374.     {
  375.         if (sd->count == 0)
  376.             d_msgat(sd->row, sd->col, color[sd->color], sd->text);
  377.         else if (sd->count > 0)
  378.         {
  379.             d_nchat(sd->row, sd->col, *sd->text, color[sd->color],
  380.              sd->count, 1);
  381.         }
  382.         else
  383.         {
  384.             d_nchat(sd->row, sd->col, *sd->text, color[sd->color],
  385.              -sd->count, 0);
  386.         }
  387.     }
  388.     d_msgat(1, 19, color[2], (TFlag.F.Receiving) ? "Receive " : "Send ");
  389.     loc(23, 0);
  390. }
  391.  
  392. /*/////////////////////////////////////////////////////////
  393. //  ExpandSubDirs                                        //
  394. //:exp////////////////////////////////////////////////// */
  395. char *ExpandSubDirs(char *fnames)
  396. {
  397.     DF fbuf;
  398.     char *p1, *lstptr, *wrkname, *savdir, *orgdir;
  399.     int i, dosub;
  400.  
  401.     orgdir = malloc(_MAX_PATH), getcwd(orgdir, _MAX_PATH);
  402.     wrkname = malloc(_MAX_PATH), savdir = malloc(_MAX_PATH);
  403.     plen = 1, lstptr = SkipSpaces(fnames), flist = calloc(1, 1);
  404.     while (1)
  405.     {
  406.         if (lstptr != fnames)
  407.         {
  408.             if (wrkname[1] == ':')
  409.                 chdir(savdir);
  410.             _chdrive(toupper(*orgdir) - 'A' + 1);
  411.             chdir(orgdir);
  412.         }
  413.         if (*lstptr == '\0')
  414.         {
  415.             free(wrkname), free(orgdir), free(savdir);
  416.             return(flist);
  417.         }
  418.         p1 = lstptr, i = SkipChars(lstptr) - lstptr, dosub = 0;
  419.         lstptr = (SkipSpaces(SkipChars(lstptr)));
  420.         if (*p1 == '(' && p1[i - 1] == ')')
  421.             ++p1, dosub = 2;
  422.         strncpy(wrkname, p1, i), wrkname[i - dosub] = '\0';
  423.         if (wrkname[1] == ':')
  424.         {
  425.             _chdrive(toupper(*wrkname) - 'A' + 1);
  426.             getcwd(savdir, _MAX_PATH);
  427.         }
  428.         p1 = GetNameExt(wrkname);
  429.         strcpy(mask, "*.*");
  430.         if (*p1)
  431.         {
  432.             fbuf.attrib = 0;
  433.             if (!strchr(p1, '*') && !strchr(p1, '?'))
  434.                 DosFindFirst(wrkname, -1, &fbuf);
  435.             if (fbuf.attrib & _A_SUBDIR)
  436.                 p1 = strchr(p1, '\0');
  437.             else
  438.             {
  439.                 strupr(strncpy(mask, p1, 12));
  440.                 p1[0] = mask[12] = '\0';
  441.             }
  442.         }
  443.         if (p1 != wrkname && *(--p1) != ':')
  444.         {
  445.             if (p1 != wrkname && *p1 == '\\' && *(p1 - 1) != ':')
  446.                 *p1 = '\0';
  447.             if (chdir(wrkname) != 0)
  448.                 continue;
  449.         }
  450.         getcwd(wrkname, _MAX_PATH);
  451.         if (dosub == 0)
  452.             AddToList(wrkname);
  453.         else
  454.             RecurseSubDirs(wrkname);
  455.     }
  456. }
  457.  
  458. /*/////////////////////////////////////////////////////////
  459. //  FileTransfer - file send / receive caller            //
  460. //:fil////////////////////////////////////////////////// */
  461. int FileTransfer(void)
  462. {
  463.     FILE *fh;
  464.     int rval, temp = v_color;
  465.     long efficiency = 0L;
  466.  
  467.     if (miniterm)
  468.         pushscrn(0, 0, 24, 80);
  469.     DspZmodemScrn();
  470.     if (node != NULL)           /* BBS support -- Maximus */
  471.     {
  472.         if ((fh = fopen(node, "rb")) != NULL)
  473.         {
  474.             memset(buf, 0, sizeof(buf));
  475.             fread(buf, 1, sizeof(buf), fh);
  476.             fclose(fh);
  477.             buf[32] = buf[68] = '\0';
  478.             d_msgat(23, 1, WHT, &buf[0]);
  479.             d_msgat(23, 40, WHT, &buf[36]);
  480.         }
  481.     }
  482.     SetFIFOLevels(cfg.FifoRxLvl, cfg.FifoTxLvl);
  483.     ZMsg(M_RESET);
  484.     if (TFlag.F.Receiving)
  485.         rval = ZmodemRecv(&port);
  486.     else
  487.     {
  488.         rval = ZmodemSend(&port, flist);
  489.         free(flist);
  490.     }
  491.     if (ConnectBaud)
  492.         efficiency = (tCPS * 1000L) / ConnectBaud;
  493.     sprintf(buf, "CPS: %ld (%d files, %ld bytes)  Efficiency %ld%% \r\n",
  494.      tCPS, tFiles, tfBytes, efficiency);
  495.     d_msgat(23, 1, WHT, buf);
  496.     tdelay(4);
  497.     if (node != NULL && async_carrier(&port) && tFiles)
  498.     {                           /* send other end result report */
  499.         async_txblk(&port, buf, strlen(buf));
  500.         while (!async_txempty(&port))
  501.             ;
  502.     }
  503.     async_rxflush(&port);
  504.  
  505.     v_color = temp;
  506.     if (miniterm)
  507.     {
  508.         SetFIFOLevels(1, 1);
  509.         d_str("  Press Enter to continue ..");
  510.         KBREAD;
  511.         popscrn();
  512.         d_str(buf);
  513.     }
  514.     return (rval);
  515. }
  516.  
  517. /*/////////////////////////////////////////////////////////
  518. //  HelpFunc - display help screen                       //
  519. //:hel////////////////////////////////////////////////// */
  520. void HelpFunc(void)
  521. {
  522.     static char helpscrn[] = "\n\
  523.     -- TXZM COMMANDS --\n\
  524.   ALT X:  Exit program         ALT E:  Echo On\n\
  525.   ALT S:  Shell to DOS         ALT P:  Change Baud\n\
  526.   ALT D:  Dial Number          ALT =:  Doorway Mode\n\
  527.   ALT R:  Redial Number        PGUP :  Send Zmodem\n\
  528.   ALT H:  Hang Up              PGDN :  Receive Zmodem\n\
  529.   ALT L:  Toggle Log File (TXZM.CAP)\n";
  530.  
  531.     d_str(helpscrn);
  532. }
  533.  
  534. /*/////////////////////////////////////////////////////////
  535. //  InitDefaults - init protocol global variables        //
  536. //:ini////////////////////////////////////////////////// */
  537. void InitDefaults(void)
  538. {
  539.     char *p1;
  540.     int i;
  541.  
  542.     combase = cfg.ComBase, irq = cfg.IRQ, vctr = cfg.Vctr;
  543.     LocBaud = cfg.LocBaud;
  544.     OvlyIO = cfg.OvlyIO;
  545.     TFlag.F.ExistOpts = cfg.ZExistOpts;
  546.     TFlag.F.IgnCarrier = cfg.IgnCarrier;
  547.     TFlag.F.KeepTime = cfg.KeepTime;
  548.     TFlag.F.EscCtl = cfg.EscCtl;
  549.     TxWindow = cfg.TxWindow;
  550. }
  551.  
  552. /*/////////////////////////////////////////////////////////
  553. //  MiniTermMode - mini-terminal mode                    //
  554. //:min////////////////////////////////////////////////// */
  555. void MiniTermMode(void)
  556. {
  557.     static char rxtripstr[6] = { '*', '*', ZDLE, 'B', '0', '0' };
  558.     static FILE *flog = NULL;
  559.     int ch, rxtrip = 0, echo = 0, doorwaymode = 0;
  560.     char *cmd;
  561.     static char statline[] = "\
  562.  Help F1 | Exit ALT-X | Shell ALT-S | Hangup ALT-H | Send PGUP | Recv PGDN";
  563.  
  564.     cmd = getenv("COMSPEC");
  565.     if (cmd == NULL)
  566.         cmd = "COMMAND";
  567.     v_color = color[8];
  568.     cls();
  569.     sprintf(buf,
  570.      "TXZM 2.14 Mini-Terminal Mode : %s : (c) 1991 Mike Dumdei\n\n",
  571.      port.BPDSstr);
  572.     d_strat(1, 0, buf);
  573.     d_nchat(24, 0, ' ', color[9], 80, 1);
  574.     d_msgat(24, 1, color[9], statline);
  575.     SETWND(0, 0, 23, 79);
  576.     while (1)
  577.     {
  578.         if (KBHIT)
  579.         {
  580.             if ((unsigned)(ch = KBREAD) == ALT_EQU)
  581.             {
  582.                 if ((doorwaymode ^= 1) != 0)
  583.                 {
  584.                     v_btm = 24;
  585.                     d_nchat(24, 0, ' ', v_color, 80, 1);
  586.                 }
  587.                 else
  588.                 {
  589.                     if (((ch = getcurloc()) >> 8) == 24)
  590.                         d_ch('\n'), loc(23, (char)(ch & 0xff));
  591.                     v_btm = 23;
  592.                     d_nchat(24, 0, ' ', color[9], 80, 1);
  593.                     d_msgat(24, 1, color[9], statline);
  594.                 }
  595.             }
  596.             else if (doorwaymode)
  597.             {
  598.                 if (!(ch & 0xff))
  599.                 {
  600.                     async_tx(&port, '\0');
  601.                     ch >>= 8;
  602.                 }
  603.                 async_tx(&port, (char)ch);
  604.             }
  605.             else switch (ch)
  606.             {
  607.               case FK1:
  608.                 HelpFunc();
  609.                 break;
  610.               case ALT_C:
  611.                 v_color = 7;
  612.                 cls();
  613.                 break;
  614.               case ALT_X:
  615.                 return;
  616.               case ALT_H:
  617.                 async_dtr(&port, 0);
  618.                 tdelay(9);
  619.                 async_dtr(&port, 1);
  620.                 break;
  621.               case ALT_D:
  622.                 d_str("\nEnter number to dial (ESC to abort) :\n");
  623.                 if ((ch = prompt(buf, 32)) == 0)
  624.                     break;
  625.                 sprintf(phone, "ATDT%s\r", buf);
  626.                 Dial();
  627.                 break;
  628.               case ALT_R:
  629.                 if (*phone)
  630.                     RepeatDial();
  631.                 break;
  632.               case ALT_P:
  633.                 SetParams(NULL);
  634.                 break;
  635.               case ALT_L:
  636.                 if (flog)
  637.                 {
  638.                     fclose(flog);
  639.                     flog = NULL;
  640.                     d_str("\nTXZM.CAP file closed\n");
  641.                 }
  642.                 else
  643.                 {
  644.                     if ((flog = fopen("TXZM.CAP", "ab")) != NULL)
  645.                         d_str("\nTXZM.CAP file opened\n");
  646.                     else
  647.                         d_str("\nTXZM.CAP file open error\n");
  648.                 }
  649.                 break;
  650.               case ALT_E:
  651.                 echo ^= 1;
  652.                 break;
  653.               case ALT_S:
  654.                 pushscrn(0, 0, 25, 80);
  655.                 SETWND(0, 0, 24, 79);
  656.                 cls();
  657.                 d_str("Type EXIT and press ENTER to return to TXZM MiniTerm\n");
  658.                 spawnlp(P_WAIT, cmd, cmd, NULL);
  659.                 popscrn();
  660.                 SETWND(0, 0, 23, 79);
  661.                 break;
  662.               case PGUP:
  663.                 d_str("\nEnter filenames to send (ESC to abort) :\n");
  664.                 if ((ch = prompt(fnames, 255)) == 0)
  665.                     break;
  666.                 flist = ExpandSubDirs(fnames);
  667.                 TFlag.F.Receiving = 0;
  668.                 FileTransfer();
  669.                 break;
  670.               case PGDN:
  671.                 TFlag.F.Receiving = 1;
  672.                 FileTransfer();
  673.                 rxtrip = 0;
  674.                 break;
  675.               default:
  676.                 if (ch & 0xff)
  677.                 {
  678.                     async_tx(&port, (char)ch);
  679.                     if (echo)
  680.                     {
  681.                         d_ch((char)ch);
  682.                         if (flog)
  683.                             fputc(ch, flog);
  684.                     }
  685.                 }
  686.                 break;
  687.             }
  688.         }
  689.         else if (async_rxcnt(&port))
  690.         {
  691.             ch = async_rx(&port) & 0xff;
  692.             d_ch((char)ch);
  693.             if (ch != rxtripstr[rxtrip++])
  694.                 rxtrip = 0;
  695.             if (flog)
  696.                 fputc(ch, flog);
  697.             if (rxtrip == 6)
  698.             {
  699.                 TFlag.F.Receiving = 1;
  700.                 FileTransfer();
  701.                 rxtrip = 0;
  702.             }
  703.  
  704.         }
  705.         else if (tryDV)
  706.             DV_TimeSlice();
  707.     }
  708. }
  709.  
  710. /*/////////////////////////////////////////////////////////
  711. //  ProcCmdLine -- process commnad line args             //
  712. //:pro////////////////////////////////////////////////// */
  713. void ProcCmdLine(int argc, char *argv[])
  714. {
  715.                         /*   COM1   COM2   COM3   COM4  */
  716.     static int bases[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
  717.     static int irqs[4]  = {  IRQ4,  IRQ3,  IRQ4,  IRQ3 };
  718.     static int vctrs[4] = { VCTR4, VCTR3, VCTR4, VCTR3 };
  719.     FILE *fh;
  720.     int parg = 0, i, j;
  721.     char *p1;
  722.  
  723.     for (i = 1; i < argc; i++)
  724.     {
  725.         p1 = strupr(argv[i]);
  726.         if (*p1 == '-' || *p1 == '/')
  727.             ++p1;
  728.         if (parg == 0)
  729.         {
  730.             if (strncmp(argv[i], "COM", 3) == 0)
  731.             {
  732.                 j = atoi(isdigit(*(p1 += 3)) ? p1 : argv[++i]);
  733.                 if (j < 1 && j > 4)
  734.                     usage();
  735.                 --j, parg = 1;
  736.                 combase = bases[j], irq = irqs[j], vctr = vctrs[j];
  737.                 continue;
  738.             }
  739.         }
  740.         switch (*p1)
  741.         {
  742.           case 'C':             /* custom comm port */
  743.             if (!isxdigit(*++p1))
  744.                 p1 = argv[++i];
  745.             for (combase = 0; isxdigit(*p1); ++p1)
  746.             {
  747.                 combase = (combase << 4) | (*p1 - ((*p1 > '9' ) ?
  748.                  ('A' - 0xA) : '0'));
  749.             }
  750.             irq = atoi(&p1[1]);
  751.             if (combase < 0 || combase > 0xff8 || irq < 2 || irq > 7 || parg)
  752.                 usage();
  753.             vctr = irq + 8;
  754.             irq = 1 << irq;
  755.             parg = 1;
  756.           case 'B':             /* connect baud rate */
  757.             strcpy(params, (isdigit(*++p1)) ? p1 : argv[++i]);
  758.             break;
  759.           case 'L':             /* locked baud rate */
  760.             strcpy(lockedbaud, (isdigit(*++p1)) ? p1 : argv[++i]);
  761.             break;
  762.           case 'D':             /* disable FIFOs */
  763.             openmask |= 0x4000;
  764.             break;
  765.           case 'M':             /* disable MSR interrupts */
  766.             openmask |= 0x2000;
  767.             break;
  768.           case 'H':             /* enable hardware handshake */
  769.             if (!isdigit(*++p1) || (j = atoi(p1)) < 0 || j > 3)
  770.                 j = 3;
  771.             if (j & 1)
  772.                 cfg.MsrFlow = B_CTS;    /* sender monitors CTS */
  773.             if (j & 2)
  774.                 cfg.MsrFlow |= B_RTS;   /* recvr drops RTS if rxbuf fills */
  775.             break;
  776.           case 'P':             /* send/accept complete pathnames */
  777.             TFlag.F.FullPath = 1;
  778.             break;
  779.           case 'I':             /* ignore loss of carrier */
  780.             TFlag.F.IgnCarrier = 1;
  781.             break;
  782.           case 'E':             /* option to take if file exists */
  783.             if (isdigit(*++p1) && (j = atoi(p1)) >= 0 && j <= 3)
  784.                 TFlag.F.ExistOpts = j;
  785.             break;
  786.           case 'X':             /* escape control characters */
  787.             if (!isdigit(*++p1) && !isdigit(*argv[i + 1]))
  788.                 TFlag.F.EscCtl = 1;
  789.             else
  790.             {
  791.                 if (!isdigit(*p1))
  792.                     p1 = argv[++i];
  793.                 do {
  794.                     j = atoi(p1);
  795.                     if ((j & 0xff60) == 0)
  796.                         ZTable[j] &= 0xf7;
  797.                     else if (j < 0 && (-j & 0xff60) == 0)
  798.                         ZTable[-j] |= 0x08;
  799.                     p1 = SkipSpaces(SkipChars(p1));
  800.                 } while (*p1);
  801.             }
  802.             break;
  803.           case 'V':             /* disable disk writes during serial I/O */
  804.             OvlyIO = 0;
  805.             break;
  806.           case 'W':             /* maximum tx bytes in transit */
  807.             TxWindow = atoi(isdigit(*++p1) ? p1 : argv[++i]);
  808.             break;
  809.           case 'N':             /* bbs use, node number follows */
  810.             node = (*++p1) ? p1 : argv[++i];
  811.             break;
  812.           case '6':             /* 16 bit CRCs only */
  813.             ZFR0 &= ~CANFC32;
  814.             break;
  815.           case '0':
  816.             v_bios = 1;         /* use bios for video */
  817.             break;
  818.           case 'Q':             /* test for DesqView environment */
  819.             tryDV = 1;
  820.             break;
  821.           case 'U':             /* miniterm mode */
  822.             miniterm = goodargs = 1;
  823.             break;
  824.           case 'R':             /* receiving -- download path may follow */
  825.             TFlag.F.Receiving = 1;
  826.             if (*++p1 > ' ')
  827.                 DfltPath = p1;
  828.             else if (++i < argc)
  829.                 DfltPath = argv[i];
  830.             else
  831.                 DfltPath = cfg.DLPath;
  832.             i = argc;
  833.             ++goodargs;
  834.             break;
  835.           case 'S':             /* sending -- file names next args */
  836.             TFlag.F.Receiving = 0;
  837.             DfltPath = cfg.ULPath;
  838.             if (*++p1 > ' ')
  839.                 argv[i--] = p1;
  840.             if (*argv[i + 1] == '@')
  841.             {
  842.                 if ((fh = fopen(&argv[++i][1], "rb")) == NULL)
  843.                     break;
  844.                 j = (int)filelength(fileno(fh));
  845.                 if ((p1 = calloc(j + 1, 1)) == NULL)
  846.                 {
  847.                     fclose(fh);
  848.                     break;
  849.                 }
  850.                 fread(p1, 1, j, fh);
  851.                 fclose(fh);
  852.                 flist = ExpandSubDirs(p1);
  853.                 free(p1);
  854.                 i = argc;
  855.                 --goodargs;
  856.             }
  857.             else
  858.             {
  859.                 while (++i < argc)
  860.                 {
  861.                     strcat(fnames, " ");
  862.                     strcat(fnames, argv[i]);
  863.                     flist = ExpandSubDirs(fnames);
  864.                 }
  865.                 if (fnames[1])
  866.                     --goodargs;
  867.             }
  868.             break;
  869.         }
  870.     }
  871. }
  872.  
  873. /*/////////////////////////////////////////////////////////
  874. //  Prompt - prompt for input string                     //
  875. //:pro////////////////////////////////////////////////// */
  876. int prompt(char *buf, int maxlen)
  877. {
  878.     char *p1 = buf;
  879.     int ch = 0;
  880.  
  881.     while (ch != '\r' && ch != '\x1b')
  882.     {
  883.         if ((ch = (KBREAD & 0xff)) == '\r')
  884.             continue;
  885.         if (ch == '\b')
  886.         {
  887.             if (p1 > buf)
  888.                 d_ch((char)ch), --p1;
  889.         }
  890.         else if (p1 >= &buf[maxlen])
  891.             d_ch('\a');
  892.         else if (ch != '\x1b' && isprint(ch))
  893.             d_ch((char)ch), *p1++ = ch;
  894.     }
  895.     d_ch('\n');
  896.     if (ch == '\x1b')
  897.         p1 = buf;
  898.     *p1 = '\0';
  899.     return (*buf);
  900. }
  901.  
  902. /*/////////////////////////////////////////////////////////
  903. //  RecurseSubDirs                                       //
  904. //:rec////////////////////////////////////////////////// */
  905. int RecurseSubDirs(char *sd)
  906. {
  907.     DF fbuf;
  908.     static char subdir[_MAX_PATH];
  909.  
  910.     if (chdir(sd) != 0)
  911.         return 0;
  912.     getcwd(subdir, _MAX_PATH);
  913.     AddToList(subdir);
  914.     if (!DosFindFirst("*.*", _A_SUBDIR, &fbuf))
  915.     {
  916.         do {
  917.             if (fbuf.attrib & _A_SUBDIR && fbuf.name[0] != '.')
  918.                 RecurseSubDirs(fbuf.name);
  919.         } while (!DosFindNext(&fbuf));
  920.     }
  921.     chdir("..");
  922.     return 1;
  923. }
  924.  
  925. /*/////////////////////////////////////////////////////////
  926. //  RepeatDial                                           //
  927. //:rep////////////////////////////////////////////////// */
  928. int RepeatDial(void)
  929. {
  930.     int rval, dials = 0, curpos = getcurloc();
  931.     char buf[40];
  932.  
  933.     while ((rval = Dial()) != 0 && rval != X_ESC)
  934.     {
  935.         tdelay(36);
  936.         while (async_rxcnt(&port))
  937.             d_ch((char)async_rx(&port));
  938.         sprintf(buf, "Dial Attempts = %d", ++dials);
  939.         d_str(buf);
  940.         setcurloc(curpos);
  941.     }
  942.     return (rval);
  943. }
  944.  
  945. /*/////////////////////////////////////////////////////////
  946. //  SetFIFOLevels - set FIFO levels                      //
  947. //:set////////////////////////////////////////////////// */
  948. void SetFIFOLevels(int rxFIFOlevel, int txFIFOlevel)
  949. {
  950.     if (port.Stat3 & B_FIFO)
  951.     {
  952.         async_FIFOrxlvl(&port, rxFIFOlevel);
  953.         async_FIFOtxlvl(&port, txFIFOlevel);
  954.     }
  955. }
  956.  
  957. /*/////////////////////////////////////////////////////////
  958. //  SetParams - set comport parameters                   //
  959. //:set////////////////////////////////////////////////// */
  960. int SetParams(char *newparams)
  961. {
  962.     char oldparams[14];
  963.  
  964.     if (newparams != NULL)
  965.         strcpy(buf, newparams);
  966.     else
  967.     {
  968.         d_str("\nEnter modem parameters (ESC to abort) :\n");
  969.         if (prompt(buf, 9) == 0)
  970.             return 0;
  971.     }
  972.     ConnectBaud = atol(buf);
  973.     if (*lockedbaud == '\0')
  974.     {
  975.         if (*(strrchr(buf, '0') + 1) == '\0')
  976.             strcat(buf, strrchr(params, '0') + 1);
  977.         strupr(buf);
  978.         if (async_setbpds(&port, buf) != 0) /* if no good */
  979.         {
  980.             ConnectBaud = atol(params);
  981.             return 0;
  982.         }
  983.         strcpy(params, buf);
  984.         LocBaud = ConnectBaud;
  985.     }
  986.     sprintf(buf,"\nModem Parameters: %s, ConnectBaud: %ld, LockedBaud: %ld\n",
  987.       port.BPDSstr, ConnectBaud, (*lockedbaud) ? LocBaud : 0L);
  988.     d_str(buf);
  989.     return 1;
  990. }
  991.  
  992. /*///////////////////////////////////////////////
  993. //  Usage                                      //
  994. //:usa//////////////////////////////////////// */
  995. void usage()
  996. {
  997.     static char msg1[] = "\n\
  998. \
  999. TXZM -- Zmodem Protocol Driver 2.14\n\
  1000.  (c) 1991, Mike Dumdei, 6 Holly Lane, Texarkana Tx 75503\n\
  1001. \n\
  1002. This program is a demo of the MCOMM5 'C' serial communications library.\n\
  1003. It may be used free of charge for non-commercial purposes.  It is not\n\
  1004. public domain and may not be modified, sold, or distributed for a fee\n\
  1005. with the exception of normal and reasonable shareware distribution fees.\n\
  1006. \n\
  1007. If you have a need for a C communications library, the latest shareware\n\
  1008. version of MCOMM5 (freq = MCOMM) is available from:\n\
  1009.   North East Texas DataLink BBS, Texarkana TX  (903) 838-6713  1:19/128\n\
  1010. Features of MCOMM5 include:\n\
  1011.   Fully interrupt driven            16550 FIFO support\n\
  1012.   Up to 115200 baud                 Fast - 95%% ASM code\n\
  1013.   Library version: $25, Source included: $45\n\
  1014. \n\
  1015. << TXZM USAGE: >>\n\
  1016.   recv> txzm { port -b# -l# -t# -d -m -h -i -p -q -x -v -e# } -r { directory }\n\
  1017.   send> txzm { port -b# -l# -t# -d -m -h -i -p -q -x -w#    } -s file1 file2\n\
  1018.   term> txzm { port -b# -l# -t# -d -m -h -i -p -q -x -w# -v -e# } -u\n\
  1019. Arguments in braces are optional.  If a baud rate is not specified, the\n\
  1020. current baud rate will be used.  The -r or -s switches must come last\n\
  1021. on the command line.\n\
  1022. Press any key for command line switch descriptions.....";
  1023.  
  1024.     static char msg2[] = "\n\
  1025. \n\
  1026.  port : set to COM1 (default), COM2, COM3, COM4, or -c#,#\n\
  1027.          -c#,# : base port address of comm port in hex,IRQ (2-7)\n\
  1028.          Ex: -c2E8,5    Addrs=2E8 IRQ=5  (no spaces in arg)\n\
  1029.   -b# : baud rate -- if using a fixed DTE link, CONNECT baud rate\n\
  1030.   -l# : baud rate of fixed DTE link (locked baud rate)\n\
  1031.   -t# : maximum characters to send to 16550 FIFOs per interrupt\n\
  1032.          1-16, default is 8  (some modems may require lower setting)\n\
  1033.   -d  : if 16550 UART detected do not enable FIFOs, default is to enable\n\
  1034.   -m  : disable modem status register interrupts\n\
  1035.   -h  : use RTS/CTS hardware handshake\n\
  1036.   -i  : ignore absence of carrier detect\n\
  1037.   -p  : send/accept full pathnames (will create subdirs)\n\
  1038.   -q  : DesqView mode (use DV video buffer, timeslice when idle)\n\
  1039.   -x  : zdle escape all control characters, -x#,.. to esc particular chars\n\
  1040.   -v  : disable serial I/O during disk writes\n\
  1041.   -e# : duplicate file handling options (default = 1)\n\
  1042.          0=skip file, 1=resume transfer, 2=create dup name, 3=overwrite\n\
  1043.   -w# : transmit window size (must be multiple of 128)\n\
  1044.   -u  : start up in mini-terminal mode\n\
  1045.   -r  : receive,  directory is optional download directory\n\
  1046.   -s  : send, file names follow - recurses subdirs of names in parenthensis\n\
  1047. txzm com2 -b2400 -h -e2 -r   (COM2, 2400 baud, CTS hndshk, dup name if exist)\n\
  1048. txzm -l38400 -b9600 -s *.zip (38400 locked rate, 9600 CONNECT, send all ZIPs)\n\
  1049. txzm -p -s (c:\\subdir)       (send all files in all subdirs in c:\\subdir)";
  1050.  
  1051.     cls();
  1052.     printf(msg1);
  1053.     KBREAD;
  1054.     printf(msg2);
  1055.     exit(-100);
  1056. }
  1057.  
  1058. /*///////////////////////////////////////////////
  1059. //  vDisplay                                   //
  1060. //:vdi//////////////////////////////////////// */
  1061. void vDisplay(int row, int col, char *format, ...)
  1062. {
  1063.     va_list arg_ptr;
  1064.     char lbuf[80];
  1065.  
  1066.     va_start(arg_ptr, format);
  1067.     vsprintf(lbuf, format, arg_ptr);
  1068.     d_msgat(row, col, txtcolor, lbuf);
  1069. }
  1070.  
  1071. /* ////////////////////////////////////////////////////////////////
  1072. //  waitfor -  waits for one of a list of up to 10 different     //
  1073. //   strings to come in on the serial port.  The list must end   //
  1074. //   with NULL.  The ticks argument is how long to wait and is   //
  1075. //   in 1/18s of a second.  Calls MCOMM serial and timer LIB     //
  1076. //   functions.  Returns the index of the first targeted string  //
  1077. //   found or one of the above error values.                     //
  1078. //:wai////////////////////////////////////////////////////////// */
  1079. int waitfor(int ticks, ...)
  1080. {
  1081.     struct { int len; char *str; } list[11], *wp;
  1082.     va_list argptr;
  1083.     char ch, *p1, *buf;
  1084.     long to;
  1085.     int i, j, rxcnt = 0, longest = 0;
  1086.  
  1087.      /* load 'list' array with target strings and their lengths */
  1088.     va_start(argptr, ticks);
  1089.     for (i = 0, wp = list; i < 10; ++i, ++wp)
  1090.     {
  1091.         if ((wp->str = va_arg(argptr, char *)) == NULL)
  1092.             break;
  1093.         if ((wp->len = strlen(wp->str)) == 0)
  1094.             return (i);
  1095.         if (wp->len > longest)
  1096.             longest = wp->len;
  1097.     }
  1098.     wp->str = NULL;
  1099.  
  1100.      /* allocate buffer for incoming chars, start timer */
  1101.     p1 = buf = malloc(longest);   /* buf size is length of longest target */
  1102.     set_timeout(&to, ticks);
  1103.  
  1104.      /* wait for target string or error */
  1105.     while (1)
  1106.     {
  1107.         if (async_rxcnt(&port))         /* if character available */
  1108.         {
  1109.             ch = (char)async_rx(&port);
  1110.             d_ch(ch);
  1111.  
  1112.             if (rxcnt < longest)            /* if "incoming" buf not full */
  1113.             {                                       /* load ch in buf,  */
  1114.                 *p1 = ch;                           /* advance positon  */
  1115.                 if (++rxcnt < longest)
  1116.                     ++p1;
  1117.             }
  1118.             else                            /* if "incoming" buf is full */
  1119.             {                                       /* shuffle left 1 pos, */
  1120.                 memmove(buf, &buf[1], longest);     /* load ch in last pos */
  1121.                 *p1 = ch;
  1122.             }
  1123.             for (wp = list; wp->str; ++wp)  /* check for found target */
  1124.             {                               /* j selects pos in buf to look */
  1125.                 if ((j = rxcnt - wp->len) >= 0
  1126.                  && memicmp(wp->str, &buf[j], wp->len) == 0)
  1127.                 {
  1128.                     free(buf);
  1129.                     return (wp - list);     /* return index if found */
  1130.                 }
  1131.             }
  1132.         }
  1133.         else if (KBHIT && KBREAD == X_ESC)  /* check for local abort */
  1134.         {
  1135.             free(buf);
  1136.             return (X_ESC);
  1137.         }
  1138.         else if (timed_out(&to))            /* check for max time */
  1139.         {
  1140.             free(buf);
  1141.             return (TIMED_OUT);
  1142.         }                                   /* check for lost carrier */
  1143.         else if (checkcarrier && !async_carrier(&port)) /* see comment */
  1144.         {
  1145.             free(buf);
  1146.             return (LOST_CARRIER);
  1147.         }
  1148.     }
  1149. }
  1150.  
  1151. /*--------------------------------------------+
  1152. |  zmodem message types (defined in ZMDOS.H)  |
  1153. +---------------------------------------------/
  1154. #define M_RHDR      0       // received header
  1155. #define M_SHDR      1       // sent header
  1156. #define M_BLK0      2       // block 0 data processed (name, size, etc.)
  1157. #define M_CLASH     3       // file name clash occurred (use ExistOpts)
  1158. #define M_FILE      4       // start of transfer, FilePos = 1st position
  1159. #define M_EOF       5       // end of transfer (1 file)
  1160. #define M_DATA      6       // sent or received file data packet
  1161. #define M_FLOW      7       // change in XOFF or CTS flow status
  1162. #define M_IDLE      8       // waiting for character or for tx to empty
  1163. #define M_RESET     9       // reset to 'first file' condition */
  1164.  
  1165. /*/////////////////////////////////////////////////////////
  1166. //  ZMsg -- zmodem message handler                       //
  1167. //:zms///////////////////////////////////////////////:z: */
  1168. void ZMsg(int type, ...)
  1169. {
  1170.     static char *HdrType[] =
  1171.     {
  1172.         "Garbage Count", "Long Packet",   "Garbled Packet",   "Bad Crc",
  1173.         "Timed Out",     "Unknown Hdr",   "Sync Error",       "Memory Error",
  1174.         "File Error",    "Lost Carrier",  "Remote Abort",     "Local Abort",
  1175.         "ZRQINIT",       "ZRINIT",        "ZSINIT",           "ZACK",
  1176.         "ZFILE",         "ZSKIP",         "ZNAK",             "ZABORT",
  1177.         "ZFIN",          "ZRPOS",         "ZDATA",            "ZEOF",
  1178.         "ZFERR",         "ZCRC",          "ZCHALLENGE",       "ZCOMPL",
  1179.         "ZCAN",          "ZFREECNT",      "ZCOMMAND",         "ZSTDERR"
  1180.     };
  1181.     static char *HdrStyle[] = { "ZBIN", "ZHEX", "ZBIN32", "" };
  1182.     static char *CrcStyle[] = { "ZCRCE", "ZCRCG", "ZCRCQ", "ZCRCW" };
  1183.     static char MsgMask[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  1184.  
  1185.     static long fStartTick, tStartTick, fCPS, fBytes, tBytes;
  1186.     static long fBarInc, tBarInc, fBarBytes, tBarBytes;
  1187.     static long fSize, fStartPos, updBytes, lastPos, orgTBytes;
  1188.     static long lastSec, lastTick, temp, flowhalts;
  1189.     static int tBarRow, fBarRow;
  1190.     static char gotBlock, crcType = ZCRCG, firstfile = 1;
  1191.  
  1192.     FILE *flog;
  1193.     va_list argptr;
  1194.     int i, j, row, hdr;
  1195.     long ticks;
  1196.     char *p1;
  1197.  
  1198.     if (MsgMask[type] == '\0')
  1199.         return;
  1200.     switch (type)
  1201.     {
  1202.       case M_RHDR:              /* received header */
  1203.       case M_SHDR:              /* sent header */
  1204.         row = (type == M_RHDR) ? 11 : 12;
  1205.         va_start(argptr, type);
  1206.         if ((hdr = va_arg(argptr, int)) < 0)
  1207.             ZHdr.Data = 0L;
  1208.         i = hdr + 12;
  1209.         j = va_arg(argptr, int) - 'A';
  1210.         if (j < 0 || j > 3)
  1211.             j = 3;
  1212.         vDisplay(row, 22, "%-17s%-9s%08lX%11ld", HdrType[i], HdrStyle[j],
  1213.          ZHdr.Data, ZHdr.Data);
  1214.         break;
  1215.       case M_CLASH:             /* file name clash occurred */
  1216.         if (TFlag.F.ExistOpts != 2)
  1217.             break;  /* not new name */
  1218.       case M_BLK0:              /* sent or received block 0 */
  1219.         i = sprintf(buf, "%-52s", PathName) - 52;
  1220.         d_msgat(3, 17, color[3], &(strupr(buf))[i]);
  1221.         if (type == M_CLASH)
  1222.             break;
  1223.         v_color = txtcolor;
  1224.         flowhalts = 0L;
  1225.         scrlupat(5, 22, 6, 32, 0);
  1226.         scrlupat(5, 58, 7, 68, 0);
  1227.         fSize = (TFlag.F.Receiving) ? RxdFileSize : FileSize;
  1228.         vDisplay(6, 58, "%-8ld", fSize);
  1229.         fStartTick = get_ticker();
  1230.         if (firstfile)
  1231.         {
  1232.             firstfile = tFiles = 0;
  1233.             tBytes = tBarBytes = 0L;
  1234.             lastSec = lastTick = tStartTick = fStartTick;
  1235.             tBarRow = 21;
  1236.             if ((tBarInc = TotalBytes / 19L) == 0)
  1237.                 ++tBarInc;
  1238.             orgTBytes = TotalBytes;
  1239.             tCPS = (ConnectBaud * 955L ) / 10000L;
  1240.             vDisplay(17, 61, "%-8s",
  1241.              ConvertSecs((TotalBytes / tCPS) + (TotalFiles >> 2)));
  1242.         }
  1243.         if ((fBarInc = fSize / 19L) == 0)
  1244.             ++fBarInc;
  1245.         fBarBytes = 0L, fBarRow = 21;
  1246.         d_nchat(3, 73, '▒', color[4], 19, 0);
  1247.         if (orgTBytes != 0L)
  1248.         {
  1249.             j = 3 + (int)((orgTBytes & 0xffff0000L) ?
  1250.              (TotalBytes / (orgTBytes / 19L)) :
  1251.              ((TotalBytes * 19L) / orgTBytes));
  1252.             while (j < tBarRow && tBarRow > 2)
  1253.                 d_msgat(tBarRow--, 75, color[6], "▒");
  1254.             vDisplay(17, 26, "%-4d", TotalFiles - 1);
  1255.             vDisplay(18, 26, "%-8ld", TotalBytes - fSize);
  1256.         }
  1257.         else
  1258.         {
  1259.             tBarInc = fBarInc, tBarBytes = 0L, tBarRow = 21;
  1260.             d_nchat(3, 75, '▒', color[4], 19, 0);
  1261.         }
  1262.         break;
  1263.       case M_EOF:               /* end of file transfer */
  1264.         va_start(argptr, type);
  1265.         i = va_arg(argptr, int);
  1266.         if (i == ZEOF || i == ZRINIT)
  1267.         {
  1268.             vDisplay(20, 26, "%d", ++tFiles);
  1269.             tfBytes = tBytes;
  1270.             if (((p1 = getenv("TXZMLOG")) != NULL)
  1271.              && ((flog = fopen(p1, "at")) != NULL))
  1272.             {
  1273.                 sprintf(buf,
  1274.                  "%c %6ld %5ld bps %4ld cps %3u errors %5ld %4d %s %d\n",
  1275.                  TFlag.F.Receiving ? 'Z' : 'z', FilePos, ConnectBaud, fCPS,
  1276.                  ErrCnt, flowhalts, BlkLen, NameExt, (SerNbr) ? SerNbr : -1);
  1277.                 fputs(buf, flog);
  1278.                 fclose(flog);
  1279.             }
  1280.         }
  1281.         if (orgTBytes != 0L)
  1282.         {
  1283.             temp = TotalBytes - fSize;
  1284.             j = 3 + (int)((orgTBytes & 0xffff0000L) ?
  1285.              (temp / (orgTBytes / 19L)) :
  1286.              ((temp * 19L) / orgTBytes));
  1287.             while (j < tBarRow && tBarRow > 2)
  1288.                 d_msgat(tBarRow--, 75, color[6], "▒");
  1289.         }
  1290.         crcType = ZCRCG;
  1291.         break;
  1292.       case M_FILE:              /* start of transfer, 1st FilePos set */
  1293.         lastPos = fStartPos = FilePos;
  1294.         fBytes = 0L;
  1295.         vDisplay(5, 22, "%-8s", ConvertSecs((fSize - fStartPos) / tCPS));
  1296.         vDisplay(7, 58, "%-8ld", fStartPos);
  1297.         if (fStartPos == 0L)
  1298.             break;
  1299.         updBytes = fStartPos;
  1300.       case M_DATA:              /* sent or received file data packet */
  1301.         if (type != M_FILE)
  1302.         {
  1303.             gotBlock = 1;
  1304.             updBytes = FilePos - lastPos;
  1305.             lastPos = FilePos;
  1306.             fBytes += updBytes, tBytes += updBytes;
  1307.             vDisplay(5, 58, "%-8ld", FilePos);
  1308.             vDisplay(21, 26, "%-8ld", tBytes);
  1309.             va_start(argptr, type);
  1310.             vDisplay(14, 11, "%s-%s", (BinHdr == ZBIN32) ? "32" : "16",
  1311.              CrcStyle[(crcType = (char)va_arg(argptr, int)) - ZCRCE]);
  1312.         }
  1313.         fBarBytes += updBytes;
  1314.         tBarBytes += updBytes;
  1315.         while (fBarBytes >= fBarInc && fBarRow > 2)
  1316.             fBarBytes -= fBarInc, d_msgat(fBarRow--, 73, color[5], "▒");
  1317.         while (tBarBytes >= tBarInc && tBarRow > 2)
  1318.             tBarBytes -= tBarInc, d_msgat(tBarRow--, 75, color[6], "▒");
  1319.         break;
  1320.       case M_FLOW:
  1321.         va_start(argptr, type);
  1322.         switch (i = va_arg(argptr, int))
  1323.         {
  1324.           case 0:           /* XOFF cleared (XON received) */
  1325.           case 1:           /* XOFF received */
  1326.             d_msgat(14, 44, color[3], (i) ? "XOFF" : "    ");
  1327.             break;
  1328.           case 2:           /* CTS signal raised */
  1329.           case 3:           /* CTS signal lowered */
  1330.             d_msgat(14, 49, color[3], (i == 3) ? "CTS" : "   ");
  1331.             break;
  1332.           case 4:           /* port error */
  1333.             d_msgat(14, 55, color[3]|BLNK, "PORT RESET");
  1334.             tdelay(18);
  1335.             d_msgat(14, 55, color[3], "          ");
  1336.         }
  1337.         flowhalts += (i & 1);
  1338.         break;
  1339.       case M_IDLE:
  1340.         if (firstfile || (ticks = get_ticker()) == fStartTick)
  1341.             break;
  1342.         if (gotBlock || (crcType == ZCRCE && ticks != lastTick))
  1343.         {
  1344.             gotBlock = 0;
  1345.             lastTick = ticks;
  1346.             if (!(fBytes & 0xfff00000L))
  1347.                 fCPS = ((fBytes * 182L) / (ticks - fStartTick)) / 10L;
  1348.             else
  1349.                 fCPS = fBytes / (((ticks - fStartTick) * 10L) / 182L);
  1350.             if (!(tBytes & 0xfff00000L))
  1351.                 tCPS = ((tBytes * 182L) / (ticks - tStartTick)) / 10L;
  1352.             else
  1353.                 tCPS = tBytes / (((ticks - tStartTick) * 10L) / 182L);
  1354.             vDisplay(7, 22, "%-6ld", fCPS);
  1355.             vDisplay(21, 61, "%-6ld", tCPS);
  1356.         }
  1357.         if (ticks > (lastSec + 18))
  1358.         {
  1359.             lastSec = ticks;
  1360.             ConvertTicks(ticks - fStartTick);
  1361.             d_msgat(6, 22, txtcolor, minsecs);
  1362.             ConvertTicks(ticks - tStartTick);
  1363.             d_msgat(18, 61, txtcolor, minsecs);
  1364.         }
  1365.         if (tryDV)
  1366.             DV_TimeSlice();
  1367.         break;
  1368.       case M_RESET:
  1369.         if (cfg.MsrFlow && !async_cts(&port))
  1370.             d_msgat(14, 49, color[3], "CTS");
  1371.         crcType = ZCRCG, firstfile = 1;
  1372.         break;
  1373.     }
  1374. }
  1375.  
  1376.  
  1377.